﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JqueryNet.FormControl.FormHtmlControl
{
    public class JHtmlTable : JHtmlControl
    {
        private System.Web.UI.HtmlControls.HtmlTable htmlTable;

        public JHtmlTable(System.Web.UI.HtmlControls.HtmlTable htmlTable)
            : base(htmlTable)
        {
            // TODO: Complete member initialization
            this.htmlTable = htmlTable;
        }

        public override void Attr(string key)
        {
            switch (key.ToLower())
            {
                case "align":
                    Value = htmlTable.Align;
                    return;
                case "bgcolor":
                    Value = htmlTable.BgColor;
                    return;
                case "border":
                    Value = htmlTable.Border;
                    return;
                case "bordercolor":
                    Value = htmlTable.BorderColor;
                    return;
                case "cellpadding":
                    Value = htmlTable.CellPadding;
                    return;
                case "cellspacing":
                    Value = htmlTable.CellSpacing;
                    return;
                case "rows":
                case "row":
                    Value = htmlTable.Rows;
                    return;
                case "width":
                    Value = htmlTable.Width;
                    return;
                default:
                    base.Attr(key); return;
            }
        }

        public override void Html()
        {
            Value = htmlTable.InnerHtml;
        }

        public override void Html(Func<string> fun)
        {
            htmlTable.InnerHtml = fun();
        }

        public override void Html(string value)
        {
            htmlTable.InnerHtml = value;
        }

        public override void Text()
        {
            Value = htmlTable.InnerText;
        }

        public override void Text(Func<string> fun)
        {
            htmlTable.InnerText = fun();
        }

        public override void Text(string value)
        {
            htmlTable.InnerText = value;
        }


        public override void Attr(string key, string value)
        {
            int b;
            int.TryParse(value, out b);
            switch (key.ToLower())
            {
                case "align":
                    htmlTable.Align = value;
                    return;
                case "bgcolor":
                    htmlTable.BgColor = value;
                    return;
                case "border":
                    htmlTable.Border = b;
                    return;
                case "bordercolor":
                    htmlTable.BorderColor = value;
                    return;
                case "cellpadding":
                    htmlTable.CellPadding = b;
                    return;
                case "cellspacing":
                    htmlTable.CellSpacing = b;
                    return;
                case "width":
                    htmlTable.Width = value;
                    return;
                default:
                    base.Attr(key, value); return;
            }
        }
    }
}
